home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_CheckGlyph.c < prev    next >
C/C++ Source or Header  |  1996-06-13  |  3KB  |  143 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #define VECTOR_BYTES(n)    (((n) * 5 + 1) & ~1)
  15.  
  16. VOID
  17. LTP_DrawCheckGlyph(struct RastPort *RPort,LONG Left,LONG Top,struct CheckGlyph *Glyph,BOOL Selected)
  18. {
  19.     struct BitMap *BitMap;
  20.  
  21.     if(Selected)
  22.         BitMap = Glyph->Selected;
  23.     else
  24.         BitMap = Glyph->Plain;
  25.  
  26.     BltBitMapRastPort(BitMap,0,0,RPort,Left,Top,Glyph->Width,Glyph->Height,0xC0);
  27. }
  28.  
  29. VOID
  30. LTP_DeleteCheckGlyph(struct CheckGlyph *Glyph)
  31. {
  32.     if(Glyph)
  33.     {
  34.         WaitBlit();
  35.  
  36.         LTP_DeleteBitMap(Glyph->Plain,FALSE);
  37.         LTP_DeleteBitMap(Glyph->Selected,FALSE);
  38.  
  39.         FreeVec(Glyph);
  40.     }
  41. }
  42.  
  43. struct CheckGlyph *
  44. LTP_CreateCheckGlyph(LONG Width,LONG Height,struct BitMap *Friend,LONG BackPen,LONG GlyphPen)
  45. {
  46.     struct CheckGlyph *Glyph;
  47.     struct RastPort *RPort;
  48.  
  49.     Glyph = NULL;
  50.  
  51.     if(RPort = (struct RastPort *)AllocVec(sizeof(struct RastPort) + sizeof(struct TmpRas) + sizeof(struct AreaInfo) + VECTOR_BYTES(11),MEMF_ANY | MEMF_CLEAR))
  52.     {
  53.         PLANEPTR Plane;
  54.  
  55.         if(Plane = AllocRaster(Width,Height))
  56.         {
  57.             struct BitMap *BitMaps[2];
  58.             LONG i,Depth,Max;
  59.  
  60.             if(BackPen > GlyphPen)
  61.                 Max = BackPen;
  62.             else
  63.                 Max = GlyphPen;
  64.  
  65.             for(i = 1 ; i <= 8 ; i++)
  66.             {
  67.                 if((1 << i) > Max)
  68.                 {
  69.                     Depth = i;
  70.                     break;
  71.                 }
  72.             }
  73.  
  74.             for(i = 0 ; i < 2 ; i++)
  75.                 BitMaps[i] = LTP_CreateBitMap(Width,Height,Depth,Friend,FALSE);
  76.  
  77.             if(BitMaps[0] && BitMaps[1])
  78.             {
  79.                 if(Glyph = (struct CheckGlyph *)AllocVec(sizeof(struct CheckGlyph),MEMF_ANY | MEMF_CLEAR))
  80.                 {
  81.                     struct TmpRas    *TmpRas;
  82.                     struct AreaInfo    *AreaInfo;
  83.                     LONG             j;
  84.                     LONG             RadiusX,
  85.                                      RadiusY;
  86.  
  87.                     TmpRas        = (struct TmpRas *)(RPort + 1);
  88.                     AreaInfo    = (struct AreaInfo *)(TmpRas + 1);
  89.  
  90.                     Glyph->Width    = Width;
  91.                     Glyph->Height    = Height;
  92.                     Glyph->Plain    = BitMaps[0];
  93.                     Glyph->Selected    = BitMaps[1];
  94.  
  95.                     InitTmpRas(TmpRas,Plane,RASSIZE(Width,Height));
  96.                     InitArea(AreaInfo,(UBYTE *)(AreaInfo + 1),11);
  97.  
  98.                     InitRastPort(RPort);
  99.  
  100.                     RPort->TmpRas    = TmpRas;
  101.                     RPort->AreaInfo    = AreaInfo;
  102.  
  103.                     RadiusX = Width / 4;
  104.                     RadiusY = Height / 4;
  105.  
  106.                     for(j = 0 ; j < 2 ; j++)
  107.                     {
  108.                         RPort->BitMap = BitMaps[j];
  109.  
  110.                         if(j)
  111.                         {
  112.                             SetRast(RPort,BackPen);
  113.                             SetAPen(RPort,GlyphPen);
  114.                         }
  115.                         else
  116.                         {
  117.                             SetRast(RPort,GlyphPen);
  118.                             SetAPen(RPort,BackPen);
  119.                         }
  120.  
  121.                         AreaEllipse(RPort,Width / 2,Height / 2,RadiusX,RadiusY);
  122.                         AreaEnd(RPort);
  123.                     }
  124.                 }
  125.             }
  126.  
  127.             WaitBlit();
  128.  
  129.             if(!Glyph)
  130.             {
  131.                 LTP_DeleteBitMap(BitMaps[0],FALSE);
  132.                 LTP_DeleteBitMap(BitMaps[1],FALSE);
  133.             }
  134.  
  135.             FreeRaster(Plane,Width,Height);
  136.         }
  137.  
  138.         FreeVec(RPort);
  139.     }
  140.  
  141.     return(Glyph);
  142. }
  143.